<?php
/**
 * +-------------------------------------------------------------
 * |Caption:
 * +-------------------------------------------------------------
 * |Author: Lenny
 * +-------------------------------------------------------------
 * |Email:  1685964109@qq.com
 * +-------------------------------------------------------------
 * |Date:   2024/7/20 下午2:49
 * +-------------------------------------------------------------
 */

namespace app\common\validate;

use think\Validate;

class UploadValidate extends Validate
{
    protected $rule = [];

    public function __construct()
    {
        parent::__construct();
        $uploadConfig = sysConfig('upload');
        if (!empty($uploadConfig)) {
            $this->rule = [
                    'upload_type' => "in:{$uploadConfig['upload_allow_type']}",
                    'file'        => "require|file|fileExt:{$uploadConfig['upload_allow_ext']}|fileSize:{$uploadConfig['upload_allow_size']}"
            ];
        } else {
            $this->rule = [
                    'file'        => "require|file|fileExt:jpg,jpeg,png,gif|fileSize:2097152"
            ];
        }

    }

    protected $message = [
            'upload_type.in' => '上传类型错误',
            'file.require'   => '请上传文件',
            'file.fileExt'   => '文件格式错误',
            'file.fileSize'  => '文件大小超出限制'
    ];

    protected $scene = ['upload'];

}